/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * IVC.java
 *
 * Created on Nov 5, 2010, 3:38:31 PM
 */

package preka.tests;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import prefuse.data.Graph;
import prefuse.data.Node;
import prefuse.visual.VisualItem;


/**
 *
 * @author vhbarros
 */
public class teste extends JPanel {

//    private static final String graph = "graph";
//    private static final String nodes = "graph.nodes";
//    private static final String edges = "graph.edges";

    private TesteIVC m_t;

    public teste() {
        m_t = new TesteIVC();
        m_t.initialize();

        //
        JFrame frame = new JFrame("Interactive Visual Clustering - Testes");
        // ensure application exits when window is closed
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JButton button = new JButton("Adicionar");
        button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				m_t.getVisualization().cancel("color");
                                //m_t.getVisualization().cancel("layout");

                                Graph g = m_t.getGraph();
                                //Node n = g.addNode();
                                /*n.set(VisualItem.LABEL, "Node "+n.getRow());
                                VisualItem vi = m_t.getVisualization().getVisualItem("graph.nodes", n);
                                if(vi.isVisible())
                                    System.out.println("Visível");
                                else
                                    System.out.println("Invisível");*/

                                g.addEdge(0, g.getNodeCount()-1);
                                m_t.getVisualization().run("color");
                                //m_t.getVisualization().run("layout");

                                //m_t.getVisualization().repaint();
			}
        });

        JButton button2 = new JButton("Remover");
        button2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				m_t.getVisualization().cancel("color");
                                m_t.getVisualization().cancel("layout");

                                Graph g = m_t.getGraph();
                                //g.removeNode(g.getNodeCount()-1);
                                g.removeEdge(g.getEdge(0, g.getNodeCount()-1));
                                m_t.getVisualization().run("color");
                                m_t.getVisualization().run("layout");
			}
        });

        JPanel cima = new JPanel(new BorderLayout());
        cima.add(m_t.getDisplay(), BorderLayout.NORTH);
        cima.setSize(600, 600);
        JPanel baixo = new JPanel(new BorderLayout());
        baixo.add(button, BorderLayout.WEST);
        baixo.add(button2, BorderLayout.EAST);
        JPanel main = new JPanel(new BorderLayout());
        main.add(cima, BorderLayout.NORTH);
        main.add(baixo, BorderLayout.SOUTH);

        frame.setContentPane(main);
        frame.pack();           // layout components in window
        frame.setVisible(true); // show the window

        m_t.run();

    }

    /** Creates new form IVC */
    public static void main (String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new teste().setVisible(true);
            }
        });



    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
